
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/home_message_bean.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/ui_const_bean.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/work_home_bean.dart';
import 'package:dk_flutter_module_sale/phoenix/my_setting/resource/meSettingResource.dart';
import '../../../r.dart';


typedef OnNewTap<MessageBean> = void Function(MessageBean value);

class WorkMessageItemWidget extends StatelessWidget {

  final OnNewTap newTap;
  final MessageBean  messageBean;
  final UpdateModuleListBean    updateModuleBean;
  WorkMessageItemWidget(this.updateModuleBean,this.messageBean,this.newTap);

  @override
  Widget build(BuildContext context) {
    return buildedNewWidget();
  }
  Widget buildedNewWidget() {
    return Container(
      color: Colors.transparent,
      padding: const EdgeInsets.only(left: 16, right: 16, top: 10),
      child: Card(
        color: Colors.white,
        margin: const EdgeInsets.only(bottom: 0),
        elevation: 0.0,
        clipBehavior: Clip.antiAliasWithSaveLayer,
        shape: const RoundedRectangleBorder(
          side: BorderSide.none,
          borderRadius: BorderRadius.all(Radius.circular(UIConstBean.CircularRadius),
          ),
        ),
        child: Container(
          padding: const EdgeInsets.only(left: 12,right: 12,top: UIConstBean.InnerTopSpace),
          color: Colors.white,
          child:  messageBean!= null? _buildWidgetWithDate() : _buildWidgetWithEmptyDate(),
        ),
      ),
    );
  }

  Widget _buildWidgetWithEmptyDate() {
    return InkWell(
      onTap: (){
        print('------点击刷新---');
        if(newTap!= null){
          newTap(null);
        }
      },
      child: Container(
        color: Colors.white,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  child:Text(updateModuleBean?.title,
                    style: TextStyle(color: Color(0xff333333),
                        fontSize: 18, fontWeight: FontWeight.w600),
                  ),
                ),
                _builderIndicateWidget(),
                SizedBox(height: 16,),
              ],
            ),
            SizedBox(height: 15,),
          ],
        )

      ),
    );
  }

  Widget _buildWidgetWithDate() {
    return  InkWell(
      onTap: (){
        print('------查看详情---');
        if(newTap!= null){
          newTap(messageBean);
        }
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(updateModuleBean?.title,
            style: TextStyle(color: Color(0xff333333),
                fontSize: 18, fontWeight: FontWeight.w600),
          ),
          SizedBox(height: 8,),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                width: 230,
                color: Colors.white,
                child: Text(messageBean?.content,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: Color(0xff666666), fontSize: 14,),
                ),
              ),
              const Spacer(),
              Text('立即查看',
                style: TextStyle(color: Color(0xff666666), fontSize: 14,),
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  SizedBox(height: 5,),
                  Image.network(MESettingImage.rightImageURL,
                        width: 12,
                        height: 12,
                  ),
                ],
              ),
              SizedBox(width: 5,),
            ],
          ),
          SizedBox(height: 15,),
        ],
      ),
    );
  }

  Widget _builderIndicateWidget() {
    if(messageBean!= null) {
      return  Image.asset(R.imagesCommonRightArrowPng,width: 12,height: 12,fit:BoxFit.fill,);
    }
    return Text('点击刷新', textAlign: TextAlign.right,
        style: TextStyle(color: Color(0xff3dbcc6), fontSize:13)
    );
  }
}

